package DataStreamApi.Transformation算子;

import org.apache.flink.api.common.eventtime.WatermarkStrategy;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.connector.file.src.FileSource;
import org.apache.flink.connector.file.src.reader.TextLineInputFormat;
import org.apache.flink.core.fs.Path;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;


public class Flink02_FILTER {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment executionEnvironment = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(new Configuration());


        FileSource<String> build = FileSource.forRecordStreamFormat(new TextLineInputFormat(), new Path("data/word.txt")).build();

        DataStreamSource<String> stringDataStreamSource = executionEnvironment.fromSource(build, WatermarkStrategy.noWatermarks(), "Flink01_MAP");

        SingleOutputStreamOperator<String> love = stringDataStreamSource.map(new MapFunction<String, String>() {
            @Override
            public String map(String value) throws Exception {
                if (value.equals("love")) {
                    return value;
                } else {
                    return "null";
                }
            }
        });

        love.print();
        executionEnvironment.execute();
    }
}
